/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package peggame;

import java.util.TreeSet;

/**
 *
 * @author zach
 */
public class MoveChecker {
    
    TreeSet<Move> moves=new TreeSet<Move>();

  public  MoveChecker(pegmanager base){
        //add all the moves starting with the constend X ones
        for(int y=0;y<base.getBoard().length;y++){
            for(int x=0;x<base.getBoard()[y].length-2;x++){
                //add the move and its converse
                moves.add(new Move(x,x+1,y,y));
                moves.add(new Move(x+1,x,y,y));
            }
        }
        //now the y moves
        for(int y=0;y<base.getBoard().length-2;y++){
            for(int x1=0;x1<base.getBoard()[y].length;x1++){
            for(int x2=0;x2<base.getBoard()[y+1].length;x2++){
            for(int x3=0;x3<base.getBoard()[y+2].length;x3++){
                if(base.isinCol(y, x1, x2, x3, true)){
                    moves.add(new Move(x1,x2,y,y+1));
                    moves.add(new Move(x2,x1,y+1,y));
                }

            }
            }
            }
        }

        
    }

    public TreeSet<Move> getMoves(int x,int y){
        TreeSet<Move> out=new TreeSet<Move>();
        for(Move i:moves){
            if(i.firstx==x&&i.firsty==y){
                out.add(i);
            }
        }
        return out;
    }

    public TreeSet<Move> showMeYourMoves(int x,int y,pegmanager board){
        TreeSet<Move> temp=getMoves(x,y);
        TreeSet<Move> out=new TreeSet<Move>();
        for(Move i:temp){
            if(pegmanager.unvisited_path==board.getBoard()[i.lasty][i.lastx]
                    ||pegmanager.path_with_unvisted_parts>=board.getBoard()[i.lasty][i.lastx])
               out.add(i);
            else if(pegmanager.unvisited_path==board.getBoard()[i.firsty][i.firstx]||
                    pegmanager.path_with_unvisted_parts>=board.getBoard()[i.firsty][i.firstx])
                out.add(i);
            
        }
        return out;
    }

    
}
